<?php ob_start();
session_start(); //on relaye la session
if(isset($_SESSION["is_registered"]) && $_SESSION["is_registered"] == "registered"){
	$enregistrer = $_SESSION["is_registered"];
	$message="";
	$titleGen="";
}else{
	header("Location:../../menu.php?erreur=intru"); // redirection en cas d'echec
}
require_once('../../Connections/microassur.php');
require_once('../../utils/fonctions.php'); 
include ("config.php");
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}


//##########################################A faire : ajoutevent1 et ajoutevent2 , rollback commit, ###################################

// Bouton Retour du paiement
if(isset($_GET['rib']) && $_GET['rib']==1 && isset($_SESSION['modepaiement']) )
{

		
		$idrib=-1;
$req=mysql_query("select * from contrat where Numero_contrat='".$_SESSION['contrat']."'")or die(mysql_error());
if($req &&  mysql_num_rows($req)>0)
{
	$rep=mysql_fetch_array($req);
	$idrib=$rep["Identifiant_rib"];
}
$requete1=mysql_query("select * from rib where Identifiant_rib='".$idrib."'");
if($requete1  && mysql_num_rows($requete1)>0)
{
	$reponse=mysql_fetch_array($requete1);
	$actif=$reponse["Etat_rib"];
}

	if( (!$rep["Identifiant_RIB"]  || !isset($actif) || ( isset($actif) && $actif=="I" )) && isset($_SESSION['modepaiement']) && $_SESSION['modepaiement']=='P' )
	{ 
	  $message.= colorer("Vous devez rattacher un RIB au contrat","false");
	  header("location:../contrat/index.php?visualiser=1&rib=0");
	}
	elseif( ($rep["Identifiant_RIB"]  && ( isset($actif) && $actif=="A" )) && isset($_SESSION['modepaiement']) && $_SESSION['modepaiement']!='P' )
	{
		  $message.= colorer("Vous devez supprimer le RIB sur le contrat ","false");
	
	}
}



// l'utilisateur a cliqué sur le bouton Retour  de l'écran de souscription
if(isset($_GET['retour']) && $_GET['retour']==1  && isset($_SESSION['idcontrat'])&& isset($_SESSION['MM_Username']))
{
		$msg="";
		$requete=mysql_query("select * from agent where Code_agent='".$_SESSION['MM_Username']."'");
		$reponse=mysql_fetch_array($requete);
		$idagent=$reponse["Identifiant_agent"];
			$requete=mysql_query("select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='S'") or die(mysql_error());
			if($requete)
			{
				$num=mysql_num_rows($requete);
				if($num!=1)$msg.="Pas de souscripteur ou plus d'un souscripteur";
			
			}	
		
		$requete=mysql_query("select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='A'") or die(mysql_error());
			if($requete)
			{
				$num=mysql_num_rows($requete);
				if($num==0)$msg.="Au moins un assuree ";
				
			}
			$requete=mysql_query("select * from role where Identifiant_contrat='".$_SESSION['idcontrat']."' and Type_role='B'") or die(mysql_error());
			if($requete)
			{
				$num=mysql_num_rows($requete);
				if($num!=1)$msg.="Pas de bénéficiaire ou plus d'un bénéficiaire";
				
			}
			$requete=mysql_query("select * from cotisation where Identifiant_contrat='".$_SESSION['idcontrat']."'") or die(mysql_error());
			if($requete)
			{
				$num=mysql_num_rows($requete);
				if($num==0)$msg.="Pas de paiement";
				
			}
			if(!empty($_SESSION['msg']))
			$requete=mysql_query("select a.Identifiant_adresse from adresse a, role r where a.Identifiant_personne=r.Identifiant_personne and r.Identifiant_contrat='".$_SESSION['idcontrat']."'") or die(mysql_error());$num=mysql_num_rows($requete); echo $num;
			if($requete)
			{
				
				if($num==0)$msg.="Pas de d'adresse"; 				
			}
			if(!empty($msg))$_SESSION['msg']="Le contrat est incomplet, vous devez saisir tous les éléments du contrat à savoir le souscripteur, au moins un assuré, un bénéficiaire ou les ayants droit, au moins une adresse et le paiement";
			
			//création evenement souscription contrat 
			$req=mysql_query("select * from evenement where Type_evenement='G' and Sous_type_evenement='ASO' and Motif_evenement='' and Reference_evenement='' and Date_evenement='".date('Y-m-d')."' and Identifiant_agent='".$idagent."' and Identifiant_sinistre='' and Identifiant_contrat='".$_SESSION['idcontrat']."' and Identifiant_personne='' and Identifiant_echeance='' and Identifiant_prestation=''") or die(mysql_error());
			$n=-1;
			if($req)
			{
				$n=mysql_num_rows($req);
				
			}
			//$requete=false;
			if($n==0){ mysql_query("START TRANSACTION");
			$requete=mysql_query("insert into evenement values('','G','ASO','','','".date('Y-m-d')."','".$idagent."','','".$_SESSION['idcontrat']."','','','')")or die(mysql_error());
			if(!$requete)
			{
			
				unset($_SESSION['modepaiement']);
							unset($_SESSION['fredpaiement']);
							unset($_SESSION['montantcotis']);							
							unset($_SESSION['refreglement']);
							unset($_SESSION['fraisecheance']);
							unset($_SESSION['datereglement']);
							unset($_SESSION['refreglement']);
							unset($_SESSION['montantecheanceregle']);
							unset($_SESSION['montantdroitentre']);
							unset($_SESSION['montantassure']);
								unset($_SESSION['cochetout']);
			
				unset($_SESSION['contrat']);
				unset($_SESSION['idcontrat']);
				unset($_SESSION['dateefin']);
				unset($_SESSION['dateeffet']);
				unset($_SESSION['cochetout']);
				unset($_SESSION['tarif']);
				unset($_SESSION['offre']);
				unset($_SESSION['produit']);
				unset($_SESSION['formule']);
				unset($_SESSION['idpers']);
				unset($_SESSION['dateeffet']);
				session_destroy();mysql_query("rollback");
				header("location:../../menu.php?ajoutevent1=0");
			}
			else mysql_query("commit");
			}
			// modification justificatifs
			$req=mysql_query("select * from justificatif where Identifiant_contrat='".$_SESSION['idcontrat']."'")or die(mysql_error());
			if($req)
			{
				// récupérer l'identifiant de l'identifiant de l'événment souscription contrat 
				$req=mysql_query("select max(Identifiant_evenement) as max from evenement")or die(mysql_error());
					if($req)
					{
						$rep=mysql_fetch_array($req);
						$max=$rep['max'];
					}
					// pour chaque justificatifs alimenter l'identifiant événement
					mysql_query("START TRANSACTION");
					$req1=mysql_query("update justificatif set Identifiant_evenement='".$max."'")or die(mysql_error());
					if($req1)	mysql_query("commit");
					else 	mysql_query("rollback");
				
			}
			//création événement type financier , réglement échéance
			
			$req=mysql_query("select * from evenement where Type_evenement='F' and Sous_type_evenement='FRE' and Motif_evenement='' and Reference_evenement='' and Date_evenement='".date('Y-m-d')."' and Identifiant_agent='".$idagent."' and Identifiant_sinistre='' and Identifiant_contrat='".$_SESSION['idcontrat']."' and Identifiant_personne='' and Identifiant_echeance='' and Identifiant_prestation=''") or die(mysql_error());
			$n=-1;
			if($req)
			{
				$n=mysql_num_rows($req);
				
			}
			//$requete=false;
			if($n==0){	mysql_query("START TRANSACTION");
			$requete=mysql_query("insert into evenement values('','F','FRE','','','".date('Y-m-d')."','".$idagent."','','".$_SESSION['idcontrat']."','','','')")or die(mysql_error());
			if(!$requete)
			{
			unset($_SESSION['modepaiement']);
							unset($_SESSION['fredpaiement']);
							unset($_SESSION['montantcotis']);							
							unset($_SESSION['refreglement']);
							unset($_SESSION['fraisecheance']);
							unset($_SESSION['datereglement']);
							unset($_SESSION['refreglement']);
							unset($_SESSION['montantecheanceregle']);
							unset($_SESSION['montantdroitentre']);
							unset($_SESSION['montantassure']);
								unset($_SESSION['cochetout']);
				unset($_SESSION['contrat']);
				unset($_SESSION['idcontrat']);
				unset($_SESSION['dateefin']);
				unset($_SESSION['dateeffet']);
				unset($_SESSION['cochetout']);
				unset($_SESSION['tarif']);
				unset($_SESSION['offre']);
				unset($_SESSION['produit']);
				unset($_SESSION['formule']);
				unset($_SESSION['idpers']);
				session_destroy();mysql_query("rollback");
				header("location:../../menu.php?ajoutevent2=0");
			  }
			  else mysql_query("commit");
			  }
			  
			  				unset($_SESSION['modepaiement']);
							unset($_SESSION['fredpaiement']);
							unset($_SESSION['montantcotis']);
							
							unset($_SESSION['refreglement']);
							unset($_SESSION['fraisecheance']);
							unset($_SESSION['datereglement']);
							unset($_SESSION['refreglement']);
							unset($_SESSION['montantecheanceregle']);
							unset($_SESSION['montantdroitentre']);
							unset($_SESSION['montantassure']);
							unset($_SESSION['cochetout']);
							
			  
							unset($_SESSION['contrat']);
							unset($_SESSION['idcontrat']);
							unset($_SESSION['dateefin']); 
							unset($_SESSION['dateeffet']);
							unset($_SESSION['cochetout']);
							unset($_SESSION['tarif']);
							unset($_SESSION['offre']);
							unset($_SESSION['produit']);
							unset($_SESSION['formule']);
							unset($_SESSION['idpers']);
							session_destroy(); 
			header("location:../../menu.php");	
	
} 
// Bouton Annuler de l'écran de souscription
if(isset($_GET['annuler']) && $_GET['annuler']==1)
{
$idcontrat=-1;
if(isset($_SESSION['idcontrat']))
{
$idcontrat=$_SESSION['idcontrat'];
}
mysql_query("START TRANSACTION");
$req=mysql_query("delete from contrat where Identifiant_contrat='".$idcontrat."'")or die(mysql_error());
unset($_SESSION['contrat']);
			unset($_SESSION['modepaiement']);
							unset($_SESSION['fredpaiement']);
							unset($_SESSION['montantcotis']);
							
							unset($_SESSION['refreglement']);
							unset($_SESSION['fraisecheance']);
							unset($_SESSION['datereglement']);
							unset($_SESSION['refreglement']);
							unset($_SESSION['montantecheanceregle']);
							unset($_SESSION['montantdroitentre']);
							unset($_SESSION['montantassure']);
							unset($_SESSION['cochetout']);
							
			  
							unset($_SESSION['contrat']);
							unset($_SESSION['idcontrat']);
							unset($_SESSION['dateefin']); 
							unset($_SESSION['dateeffet']);
							unset($_SESSION['cochetout']);
							unset($_SESSION['tarif']);
							unset($_SESSION['offre']);
							unset($_SESSION['produit']);
							unset($_SESSION['formule']);
							unset($_SESSION['idpers']);
				session_destroy(); 
if(!$req) {mysql_query("rollback");header("location:menu.php?annuler=0");}
else mysql_query("commit");
}
if(isset($_GET['Identifiant_personne']))
{
$_SESSION['idpers']=$_GET['Identifiant_personne'];
header("location:saisiepersonne.php");
}
//if(isset($_POST['Rechercher']))echo $_POST['Rechercher'];
//elseif(isset($_GET['recherche']) && $_GET['recherche']=='null')header("location:index.php?".$_SERVER['QUERY_STRING']."&recherche=0");
if(isset($_POST['Rechercher']) && $_POST['Rechercher']=='Rechercher' && !empty($_POST['produit']) && !empty($_POST['offre']))
{
for($i=0;$i<3;$i++)if(isset($_POST['role'][$i]))$_SESSION['role']=$_POST['role'][$i]; 
//$_SESSION['role']=$_POST['role'][0];
if(!isset($_SESSION['role']))$message.=colorer("Vous devez choisir un rôle","false");

//if(isset($_GET['assure'])) header("location:recherchePersonne.php?assure=1");
//elseif(isset($_GET['beneficiaire'])) header("location:recherchePersonne.php?beneficiaire=1");
else header("location:recherchePersonne.php");

}
elseif(isset($_POST['Rechercher'])  && $_POST['Rechercher']=='Rechercher' &&  (empty($_POST['produit'])  || empty($_POST['offre']) || empty($_POST['formule']))) 
$message.=colorer("Veuillez choisir une offre, un produit et une formule","false");

if(isset($_GET['creer']) && $_GET['creer']=='CREER' && !empty($_POST['produit']) && !empty($_POST['offre'])&& !empty($_POST['formule']))
{
//
//$_SESSION['produit']=$_POST['produit'];
//$_SESSION['offre']=$_POST['offre'];
//$_SESSION['formule']=$_POST['formule'];
//if(isset($_POST['role'][0]))
//$_SESSION['role']=$_POST['role'][0];
//else $message.="Vous devez choisir un rôle.";

//header("location:saisiepersonne.php");
}
elseif(isset($_GET['creer']) && $_GET['creer']=='CREER'   &&  (empty($_POST['produit'])  || empty($_POST['offre']) || empty($_POST['formule']))) 
$message.=colorer("Veuillez choisir une offre, un produit et une formule","false");


mysql_select_db($database_microassur, $microassur);
$query_rs_conditions_ventes = "SELECT * FROM conditionvente WHERE Type_condition_vente = 'Clause bénéficiaire'";
$rs_conditions_ventes = mysql_query($query_rs_conditions_ventes, $microassur) or die(mysql_error());
$row_rs_conditions_ventes = mysql_fetch_assoc($rs_conditions_ventes);
$totalRows_rs_conditions_ventes = mysql_num_rows($rs_conditions_ventes);
?> <?php
if(isset($_POST['valider']) && $_POST['valider']=='VALIDER' &&  !empty($_POST['numcontrat']) && !empty($_POST['dateeffet']) )
{
$numcontrat=$_POST['numcontrat'];
$dateeffet=$_POST['dateeffet'];
$_SESSION['contrat']=$_POST['numcontrat'];
$_SESSION['dateeffet']=$_POST['dateeffet'];
$_SESSION['cochetout']=true;

mysql_select_db($database_microassur, $microassur);

$bool=existeChamp($database_microassur, $microassur,'contrat','Numero_contrat',@$_POST['numcontrat']);
$bool1=verifDate(date('d/m/Y'),$dateeffet);
if(!$bool && $bool1){
$message=colorer("OK","true");
$dateeffet1=dateEN2FR($dateeffet);
$QuestionBase = "SELECT  $champ1_Table1,$champ2_Table1 FROM $Table1  where  Date_debut_offre <='".$dateeffet1."' and Date_fin_offre>='".$dateeffet1."' ORDER BY $champ1_Table1 ASC " ;
$result_recherche=mysql_query($QuestionBase, $microassur) or die (mysql_error());
$n=mysql_num_rows($result_recherche); 
}
elseif($bool)$message.=colorer("Ce contrat existe déjà","true");

elseif(!$bool1)$message.=colorer("La date d’effet du contrat est postérieure à la date du jour","false");
}
elseif(isset($_POST['valider'])   && (empty($_POST['numcontrat']) || empty($_POST['dateeffet']) ))
$message.=colorer("Vous devez saisir un numéro contrat et une date effet","false");

// Connexion a la base de donnees  
	 
if(isset($_GET['ajout']) && $_GET['ajout']=='echec') $message.=colorer("Création contrat impossible, contactez la DSI","false");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><?php echo $titleGen ?></title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
			<script language="Javascript"type="text/JavaScript">
// Requette AJAX
function makeRequest(url,id_niveau,id_ecrire){
var http_request = false;
//créer une instance (un objet) de la classe désirée fonctionnant sur plusieurs navigateurs
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');//un appel de fonction supplémentaire pour écraser l'en-tête envoyé par le serveur, juste au cas où il ne s'agit pas de text/xml, pour certaines versions de navigateurs Mozilla
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}

if (!http_request) {
alert('Abandon :( Impossible de créer une instance XMLHTTP');
return false;
}
http_request.onreadystatechange = function() { traitementReponse(http_request,id_ecrire); } //affectation fonction appelée qd on recevra la reponse
// lancement de la requete
http_request.open('POST', url, true);
//changer le type MIME de la requête pour envoyer des données avec la méthode POST , !!!! cette ligne doit etre absolument apres http_request.open('POST'....
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
obj=document.getElementById(id_niveau);
data="val_sel="+obj.value;
http_request.send(data);
}

function traitementReponse(http_request,id_ecrire) {
var affich="";
if (http_request.readyState == 4) {
if (http_request.status == 200) {
// cas avec reponse de PHP en mode texte:
//chargement des elements reçus dans la liste
var affich_list=http_request.responseText;
obj = document.getElementById(id_ecrire);
obj.innerHTML = affich_list;
}
else {
alert('Un problème est survenu avec la requête.');
}
}
}
</script>

<script language="javascript">
<!--
funtion fct()
{
var id1=document.getElementById('id_niv1');
var id2=document.getElementById('cont_list2');
var s="makeRequest('rep_ajaxphp2.php','cont_list3','id_list4')";
return s;
}
funtion ma_fct()
{
if(document.getElementById('souscripteur').checked==true)
document.getElementById('creer').desabled=true;
-->
}

</script>
</head>

<body onLoad="document.forms['form1'].elements['offre'].focus()">
		<div id="sf_menu1">
				<h3>Production</h3>
				<?php
					if(isset($message))
						echo $message;
					$nommodule="Souscription";
					$nommodule2="Souscription contrat";
					$nom_module_saisie="Ecran saisie";
					?>
			</div>
			<div class="cleared"></div>
		<div class="corps1">
			<!--/***************************************/-->
                    <div class="imgleft2"></div>
					<div class="imgmiddle2">
				<div class="btn"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nommodule; ?></h5></span><span class="btnright"></span></div>
				<div class="btn1"><span class="btnleft"></span><span class="btnmiddle"><h5><?php echo $nom_module_saisie; ?></h5></span><span class="btnright"></span></div>
				<div class="cleared"></div>
					<div class="formulaire">
					<form method="post" action="index.php">
						<table class="tab">
						  <tr>
							<td class="n_ctr">N° CONTRAT</td>
							<td><input type="text" class="resizeall" name="numcontrat" id="numcontrat"  value="<?php if(isset($numcontrat))echo $numcontrat;elseif(isset($_SESSION['contrat'])) echo $_SESSION['contrat']?>"/></td>
							<td class="n_ctr">DATE D'EFFET</td>
							<td><input type="text" class="resizeall" name="dateeffet" id="dateeffet" value="<?php if(isset($dateeffet))echo $dateeffet;elseif(isset($_SESSION['dateeffet'])) echo $_SESSION['dateeffet']?>"/></td>
						  </tr>
						</table>
						<div style="float:right; margin-top:-25px;"><span class="btleft"></span></span><input type="submit" name="valider" id="valider" value="VALIDER" class="resizeall btmiddle"/><span class="btright"></span> </div>
						<div class="cleared"></div>
                    </form>
<form method="post" action="index.php" name="form1">
				<div class="content_tableform1">
				  <table>
				  <tr>
					<td>OFFRE</td>
					<td>
					<div id="id_list1">
						<select class="select1" name="offre"  id="id_niv1"  onfocus="makeRequest('rep_ajaxphp.php?numcontrat=<?php if(isset($_SESSION['contrat']))echo $_SESSION['contrat']; elseif(isset($_POST['numcontrat'])) echo $_POST['numcontrat']; ?>&d=<?php if(isset($_SESSION['dateeffet']))echo dateEN2FR($_SESSION['dateeffet']) ; elseif(isset($_POST['dateeffet'])) echo dateEN2FR($_POST['dateeffet'])?>','id_niv1','id_list2')">
							<option value="-1">-- Choisissez --</option>
				<?php

					  if(isset($_SESSION['dateeffet']))$date=dateEN2FR($_SESSION['dateeffet']);
					  elseif(isset($_POST['dateeffet'])) $date=dateEN2FR($_POST['dateeffet']);
					  else $date=-1;
					  $requete=mysql_query("select * from offre where Date_fin_offre>='".$date."' and Date_debut_offre<='".$date."'") or die(mysql_error());
					  while ($reponse=mysql_fetch_array($requete) ){
						if( isset($_SESSION['offre']) && $reponse['Identifiant_offre']==$_SESSION['offre'])
					$var="selected='selected'";else $var="";
				?><option     
					<?php echo $var;?>  value="<?php echo $reponse['Identifiant_offre']?>"><?php echo $reponse['Libelle_offre']?></option> 
				<?php
					}
				?>
						</select> 
					</div> 
					</td>
					</tr>
				  <tr>
					<td>PRODUIT</td>
					<td>
						<div id='id_list2'>
							<select class="select1" name='produit' id='cont_list2'  onChange="makeRequest('rep_ajaxphp1.php','cont_list2','id_list3')" >
								<option value="0">-- Choisissez --</option>
							</select>
					<!-- ici sera charge la reponse mode texte de PHP à la request AJAX -->
						</div>
					</td>
					<td class="td0">FORMULE</td>
					<td>
						<div id='id_list3'>
							<select class="select1" name='formule' id='cont_list3'  onChange="makeRequest('rep_ajaxphp2.php?d="+document.getElementById('dateeffet').value+"&numcontrat="+document.getElementById('numcontrat').value+"&id1="+document.getElementById('id_niv1').value+"&id2="+document.getElementById('cont_list2').value+"','cont_list3','id_list4')" > 
								<option value="0">-- Choisissez --</option>
							</select>
						</div>
					</td>
				  </tr>
				  </table>
				  </div>
   <script language="javascript">
   <!--
	  function estCoche(x,a)
      {
	  
	  		if(a){
		 
			 	 if((x==true || a.checked==true))
		 		 {
		  
		  	document.getElementById("creer").style.display="none";
			document.getElementById("creer1").style.display="block";
			document.getElementById("creer2").style.display="none";
			document.getElementById("creer3").style.display="block";	  
		  		
				 }
				 if(x==false && a.checked==false)
				 {
					 document.getElementById("creer1").style.display="none";
					document.getElementById("creer").style.display="block";
					document.getElementById("creer3").style.display="none";
					document.getElementById("creer2").style.display="block";
				}
			}		
			
	  }
	-->
      </script>
   <div id="dv">
		<div class="dv1">
			<span><input type="checkbox" <?php  if((isset($_SESSION['role']) && ($_SESSION['role']=='S' || $_SESSION['role']==-1)) || !isset($_SESSION['role'])  || !isset($_SESSION['cochetout']) ) echo "checked='checked'" ?>    name="role[]" value="S" id="souscripteur" /><span>SOUSCRIPTEUR</span></span>
			<span><input type="checkbox" value="A"  onclick="estCoche(this.checked,beneficiaire)" <?php if(isset($_SESSION['role']) && $_SESSION['role']=='A' || !isset($_SESSION['cochetout']) ) echo "checked='checked'" ?>  name="role[]" id="assure" /><span>ASSURE</span></span>

		<?php 
			 $nb=0;
				if(isset($_SESSION['offre']) and isset($_SESSION['produit']))
				{
					$QuestionBase = "SELECT * from conditionvente  WHERE Identifiant_offre='".$_SESSION['offre']."'  or Identifiant_produit='".$_SESSION['produit']."' ORDER BY Identifiant_condition_vente ASC " ;
					$result_recherche=mysql_query($QuestionBase, $microassur) or die (mysql_error());
					if($result_recherche)$nb=mysql_num_rows($result_recherche);
				}
				if(isset($_GET['beneficiaire']) || $nb>0 ){ ?>
			<span><input value="B" onclick="estCoche(this.checked,assure)" id="beneficiaire" type='checkbox' <?php if(isset($_SESSION['role']) && $_SESSION['role']=='B' || !isset($_SESSION['cochetout']) ) echo "checked='checked'"  ?>  name="role[]" /><span>BENEFICIAIRE</span></span>
		<?php } else { ?>
			<div id='id_list4'> </div>
			<?php } ?>
			<span><a href="../paiement/index.php?paiement=1"> <input value="P" <?php if(isset($_SESSION['role']) && $_SESSION['role']=='P' || !isset($_SESSION['cochetout'])  ) echo "checked='checked'" ?>  type="checkbox" name="role[]" id="checkbox2" /></a><span>PAIEMENT</span></span>
		</div>
		<div class="dv1 sb">
					<div><span class="btleft"></span><input type="submit" value="Rechercher" name="Rechercher" <?php if(isset($_GET['rib'])) echo "disabled='disabled'";?> id="rechercher" class="resizeall btmiddle"/><span class="btright"></span></div>
			<?php if(!isset($_GET['recherche']) && !isset($_GET['rib'])) { ?>
			<div id="creer"  style="display:none;"><a href="saisiepersonne.php?creer=CREER"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div> 
			<div class="cleared"></div>
			<div id="creer1"  style="display:block;"><a href="#"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
			<div id="creer2"  style="display:none;"><a href="index.php?visualiser=1"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
			<div id="creer3"  style="display:block;"><a href="#"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
				<?php } elseif(isset($_GET['rib'])) { ?>
			<div id="creer"  style="display:none;"><a href="saisiepersonne.php?creer=CREER"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div>    
			<div class="cleared"></div>
			<div id="creer1"  style="display:block;"><a href="#"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
			
			<div id="creer2"  style="display:block;"><a href="index.php?visualiser=1"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
			<div id="creer3"  style="display:none;"><a href="#"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
			<div class="cleared"></div>
			<?php } else { ?>
					<div id="creer1"  style="display:none;"><a href="#"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div>
					<div class="cleared"></div>
					<div id="creer"  style="display:block;"><a href="saisiepersonne.php?creer=CREER"><span class="btleft"></span><span class="btmiddle">Créer</span><span class="btright"></span></a></div>
					<div class="cleared"></div>
					<div id="creer2"  style="display:none;"><a href="index.php?visualiser=1"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
					<div class="cleared"></div>
					<div id="creer3"  style="display:block;"><a href="#"><span class="btleft"></span><span class="btmiddle">Visualiser</span><span class="btright"></span></a></div>
			<?php } ?>
		</div>
	</div>
	</form>
	 </div>	
 	</div>
	<div class="imgright2"></div>
<div class="cleared"></div>
    <div class="bt1"><a href="index.php?retour=1"><span class="btleft"></span><span class="btmiddle">Retour</span><span class="btright"></span></a></div>    
       <?php if(isset($_GET['desactAnnuler'])) { ?>
			<div class="bt1"><a href="#"><span class="btleft"></span><span class="btmiddle">Annuler</span><span class="btright"></span></a></div><?php 
	   } else { ?> 
			<div class="bt1"><a href="index.php?annuler=1"><span class="btleft"></span><span class="btmiddle">Annuler</span><span class="btright"></span></a></div>	<?php }?>
  <div class="cleared"></div>
</div>
</body>
</html>
<?php mysql_free_result($rs_conditions_ventes); ?>
<?php ob_end_flush();?>
